<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Minim : : Sink</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="stylesheet.css" rel="stylesheet" type="text/css">
</head>
<body> 
<center>
<table class="mainTable">
  <tr>
    <td class="header">
    	<span class="indexheader">Minim</span><br/>
    	<span class="indexnavigation">
    		<a href="index.html">core</a> | 
    		<a href="index_ugens.html">ugens</a> | 
    		<a href="index_analysis.html">analysis</a>
    	</span>
    </td>
    <td class="border-left">&nbsp;</td>
  </tr>
  
  <tr>
    <td class="classNavigation">
    	<p class="mainTextName">Sink</p>
    	
    	
       <p class="linkListHeader">Methods</p>
       <p class="linkList">
           
    <a href="sink_method_channelcount.html" title="Returns the number of channels this UGen has been configured to generate.">channelCount ( )</a><br/>
    
    <a href="sink_method_generate.html" title="Generates a buffer of samples by ticking this UGen mono.length times.
 Like the tick method, this will result in all of the">generate ( )</a><br/>
    
    <a href="sink_method_getlastvalues.html" title="Return the last values generated by this UGen. This will most often be
 used by sub-classes when pulling data from their inputs.">getLastValues ( )</a><br/>
    
    <a href="sink_method_patch.html" title="Send the output of this UGen to another UGen, UGenInput, or AudioOutput.">patch ( )</a><br/>
    
    <a href="sink_method_printinputs.html" title="Prints all inputs connected to this UGen (for debugging)">printInputs ( )</a><br/>
    
    <a href="sink_method_samplerate.html" title="Returns the sample rate of this UGen.">sampleRate ( )</a><br/>
    
    <a href="sink_method_setchannelcount.html" title="Let this UGen know how many channels of audio you will be asking it for.">setChannelCount ( )</a><br/>
    
    <a href="sink_method_setsamplerate.html" title="Set the sample rate for this UGen.">setSampleRate ( )</a><br/>
    
    <a href="sink_method_tick.html" title="Generates one sample frame for this UGen.">tick ( )</a><br/>
    
    <a href="sink_method_unpatch.html" title="Unpatch this UGen from an AudioOutput or other UGen.">unpatch ( )</a><br/>
    
	   </p>
   
    </td>
    <td class="mainText border-left">
    	A Sink is similar to a Summer, but instead of summing all of the UGens patched to it,
 it simply ticks them and only generates silence. This is useful if you have a UGen that 
 needs to be ticked but that shouldn't be generating audio, such as an EnvelopeFollower.
    	<p class="memberSectionHeader">Constructors</p>
    	<pre><em></em>
Sink()
</pre>
    	
    	<p class="memberSectionHeader">Related</p>
    	<A href="summer_class_summer.html">Summer</A><BR>

    	<p class="memberSectionHeader">Example</p>
    	<pre>/**
  * This sketch demonstrates how to use an EnvelopeFollower, which will 
  * analyze the audio coming into it and output a value that reflects 
  * the volume level of that audio. It is similar to what AudioBuffer's 
  * level method provides, but has the advantage of being able to be 
  * inserted into the signal chain anywhere.
  * &lt;p>
  * This sketch also demonstrates using a Sink UGen, which can have 
  * many UGens patched to it, like a Summer, but that generates silence.
  * It is used here because we need a way to tick the EnvelopeFollower
  * but we are not interested in hearing the output of the EnvelopeFollower.
  * &lt;p>
  * For more information about Minim and additional features,&lt;br/>
  * visit http://code.compartmental.net/minim/
  */

import ddf.minim.*;
import ddf.minim.ugens.*;

Minim             minim;
AudioOutput       out;
Oscil             wave;
Oscil             mod;
EnvelopeFollower envFollow;

void setup()
{
  size(512, 200, P3D);
  
  minim = new Minim(this);
  
  // use the getLineOut method of the Minim object to get an AudioOutput object
  out = minim.getLineOut();
  
  // create a triangle wave Oscil, set to 440 Hz, at 1.0 amplitude
  // in this case, the amplitude we construct the Oscil with 
  // doesn't matter because we will be patching something to
  // its amplitude input.
  wave = new Oscil( 440, 1.0f, Waves.TRIANGLE );
 
  // create a sine wave Oscil for modulating the amplitude of wave
  mod  = new Oscil( 2, 0.4f, Waves.SINE );
 
  // connect up the modulator
  mod.patch( wave.amplitude );
  
  // patch wave to the output
  wave.patch( out );
  
  // now create an envelope follower to show the level of the wave
  
  envFollow = new EnvelopeFollower( 0,   // attack time in seconds
                                    0.1, // release time in seconds
                                    1024 // size of buffer to analyze 
                                  );
  
  // a sink to tick the envelope follower because 
  // we won't use the output of it in the signal chain
  Sink sink = new Sink();
  wave.patch( envFollow ).patch( sink ).patch( out );
}

void draw()
{
  // adjust the modulator amplitude based on mouseY
  // this should mean that when the modulator has 
  // a high amplitude that the envelope follower 
  // will report a larger range of values
  float amp = constrain( map( mouseY, 0, height, 1, 0), 0, 1 );
  mod.amplitude.setLastValue( amp );
  
  // and we can connect the frequency of modulation to mouseX
  // and see the result of that in the follower, as well
  float freq = constrain( map( mouseX, 0, width, 0.1, 1 ), 0.1, 1 );
  mod.frequency.setLastValue( freq );
  
  background(0);
  stroke(0);
  fill(255);
  
  // draw the output of the envelope follower
  float h = envFollow.getLastValues()[0] * height;
  rect( 0, height - h, width, height );
}
</pre>
    	<p class="memberSectionHeader">Usage</p>
    	Web & Application
    </td>
  </tr>
</table>
</center>
</body>
</html>